package com.yanqu.road.server.cmd.monopolymarket.res;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.monopolymarket.MonopolyMarketModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.monopolymarket.MonopolyMarketMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;

/**
 *
 * 这种结算方式是 ： 结算了cross 通知区服 区服发现玩家在系统里面，向cross请求结算 的返回
 *
 * @Description
 * @Author cwq
 * @Data 2021/8/20 10:25
 */
@Cmd(code = GameProtocol.S_MONOPOLY_MARKET_RES_GRAB_POINT_SETTLEMENT, desc = "资源争夺战 资源点结算")
public class MonopolyMarketResGrabPointSettlementFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 这种结算是玩家在线的结算方式
        MonopolyMarketProto.MonopolyMarketResGrabReceiveRewardToGameServerMsg msg = MonopolyMarketProto.MonopolyMarketResGrabReceiveRewardToGameServerMsg.parseFrom(packet.getBytes());
        MonopolyMarketProto.BroadcastMonopolyMarketRespMsg.Builder builder = MonopolyMarketProto.BroadcastMonopolyMarketRespMsg.newBuilder();
        builder.setType(2);
        MonopolyMarketModule marketModule = player.getModule(MonopolyMarketModule.class);
        if(marketModule.baseData.getOfficeTip() != null){
            marketModule.baseData.setHasTip(true);
        }else {
            marketModule.baseData.setHasTip(false);
        }
        for (MonopolyMarketProto.MonopolyMarketSynPointSettlementToGameServerMsg item : msg.getPointSettlementListList()){
            // 清空门客、美女位置
            MonopolyMarketMgr.leaveResGrabPoint(player,item.getType(),item.getPosIndex(),false);
            Property property = MonopolyMarketMgr.addReward(item.getType(),item.getRewardNum());
            player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.MonopolyMarket,eLogMoneyType.MonopolyMarketResGrabRobbedReward);
            builder.addResGrabTip(MonopolyMarketMgr.builderMonopolyMarketResGrabTipEntity(item));
            marketModule.synRoleData();
        }
        player.sendPacket(YanQuMessageUtils.buildMessage(ClientProtocol.U_MONOPOLY_MARKET_BROADCAST, builder));
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
